<template>
  <!--系列子品-->
  <div v-if="editDialogVisible10">
    <el-form>
      <el-form-item>
        <el-form-item>
          <kt-button type="primary" @click="handleEditSonProductAttr" label="创建子品"></kt-button>
        </el-form-item>
      </el-form-item>
    </el-form>

    <el-table :data="getProductParentList" border style="width: 100%">
      <el-table-column v-for="(item, index) in getProductParentAttrList" :key="item.attrId" :label="item.attrName">
        <template slot-scope="scope">
          {{scope.row.productPropertyResponseList[index].valueName}}
        </template>
      </el-table-column>
      <el-table-column label="商品编码" prop="code"></el-table-column>
      <el-table-column label="第三方商品编码" prop="thirdProductCode">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.thirdProductCode" controls-position="right" style="width: 100px"
            class="inputClass"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="条形码" prop="barCode">
        <template slot-scope="scope">
          <el-input v-model="scope.row.barCode" style="width: 100px"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="售价" prop="salePriceWithTax">
        <template slot-scope="scope">
          <el-input v-model="scope.row.salePriceWithTax" style="width: 100px"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="市场价" prop="marketPrice">
        <template slot-scope="scope">
          <el-input v-model="scope.row.marketPrice" style="width: 100px"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="采购价" prop="purchasePriceWithTax">
        <template slot-scope="scope">
          <el-input v-model="scope.row.purchasePriceWithTax" style="width: 100px"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="团购价" prop="groupBuyingPrice">
        <template slot-scope="scope">
          <el-input v-model="scope.row.groupBuyingPrice" style="width: 100px"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="总库存" prop="totalStock">
        <template slot-scope="scope">
          <el-input v-model="scope.row.totalStock" style="width: 100px"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="可用库存" prop="availableStock">
        <template slot-scope="scope">
          <el-input v-model="scope.row.availableStock" style="width: 100px"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="辅计量单位">
        <template slot-scope="scope">
          <el-button :size="size" type="primary" @click="handleEditUnits(scope.row)">设置</el-button>
        </template>
      </el-table-column>
      <el-table-column label="仓库名称" prop="warehouseName"></el-table-column>
      <el-table-column label="商品主图" prop="pictureUrl">
        <template slot-scope="scope">
          <img v-if="scope.row.pictureUrl!=''" :src="scope.row.pictureUrl" min-width="70" height="70"/>
          <el-upload
            class="upload-demo"
            width="30px"
            :action="imgUpload"
            :on-success="handleSuccess"
            accept="image/gif, image/jpeg, image/jpg, image/png, image/svg"
            :limit="pictureUrlLimit"
            :file-list="fileList"
             ref="upload"
          >
            <el-button size="mini" @click="AddPictureUrl(scope.$index)"  type="primary">点击上传</el-button>
          </el-upload>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button :size="size" type="primary" @click="handleDeleteProductParent(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--批量维护价格-->
    <el-form :inline="true">
      <!--<el-form-item label="批量维护价格" prop="chineseName">-->
      <!--<el-input v-model="dataForm.chineseName" placeholder="售价"></el-input>-->
      <!--</el-form-item>-->
      <!--<el-form-item>-->
      <!--<el-input v-model="dataForm.chineseName" placeholder="市场价"></el-input>-->
      <!--</el-form-item>-->
      <!--<el-form-item>-->
      <!--<el-input v-model="dataForm.chineseName" placeholder="采购价"></el-input>-->
      <!--</el-form-item>-->
      <!--<el-form-item>-->
      <!--<el-input v-model="dataForm.chineseName" placeholder="团购价"></el-input>-->
      <!--</el-form-item>-->
      <!--<el-form-item>-->
      <!--<kt-button type="primary" @click="handleEditDistribute" label="确定"></kt-button>-->
      <!--</el-form-item>-->
      <!--&lt;!&ndash;批量上传图片&ndash;&gt;-->
      <!--<el-row>-->
      <!--<el-form-item label="批量上传图片" prop="chineseName">-->
      <!--<kt-button type="primary" @click="handleEditMpSeries" label="关联图片"></kt-button>-->
      <!--</el-form-item>-->
      <!--</el-row>-->
      <!--底部按钮栏-->
      <el-row id="footerButton">
        <el-col :span="8" :offset="10">
          <el-form-item>
            <el-button :size="size" type="primary" @click.native="handleUpdateProductParent"
                       :disabled="this.getProductParentList.length < 1" :loading="editLoading">
              {{ $t("action.submit") }}
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!--添加系列子品弹窗-->
    <el-dialog
      title="添加系列子品" width="70%" :visible.sync="editDialogVisible83" :close-on-click-modal="false">
      <el-form label-width="80px" :inline="true" :size="size">
        <el-table ref="multipleTable" :data="sonProductAttrData" border tooltip-effect="dark" style="width: 100%">
          <el-table-column prop="attrName" label="属性项名称"></el-table-column>
          <el-table-column prop="orgNumber" label="属性值">
            <template slot-scope="scope">
              <el-checkbox-group v-model="categoryPropertyCheckList[scope.$index]">
                <el-checkbox v-for="(item,index) in scope.row.categoryPropertyValueResponseList" :label="item.valueId"
                             :key="index">
                  {{item.valueName}}
                </el-checkbox>
              </el-checkbox-group>
              <!--<el-radio-group  v-model="categoryPropertyRadio[scope.$index]"  >-->
              <!--<el-radio  v-for="(item,index) in scope.row.categoryPropertyValueResponseList" :key="index" @change="changeCategoryPropertyRadio(scope.$index,scope.row.attrId,item.valueId)"  :label="item.valueId">{{item.valueName}}</el-radio>-->
              <!--</el-radio-group>-->

            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div style="text-align:center;margin-top: 20px;">
        <el-button :size="size" type="primary" @click.native="saveSonProductAttrDataList" :loading="editLoading">
          生成系列子品
        </el-button>
      </div>
      <div style="margin-top:30px;">
        <el-table
          ref="multipleTable"
          :data="sonProductAttrDataList"
          border
          tooltip-effect="dark"
          style="width: 100%">
          <el-table-column
            fixed="left"
            label="操作"
            width="100">
            <template slot-scope="scope">
              <el-button
                :size="size"
                type="primary"
                @click="handleDeleteCategoryProperty(scope.$index, scope.row)">移除
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="属性值">
            <template slot-scope="scope">
              <template v-for="att in sonProductAttrDataList[scope.$index].attList">
                <p>{{att.attr}} <span style="text-align: right">{{att.repeat}}</span></p>
              </template>
            </template>
          </el-table-column>
        </el-table>
        <div style="text-align:center;margin-top: 20px;">
          <el-button :size="size" type="primary" @click.native="submitSonProductAttrDataList" :loading="editLoading">
            创建系列子品
          </el-button>
          <el-button :size="size" @click="cancelEditSonProductAttr" :loading="editLoading">取消</el-button>
        </div>

      </div>
    </el-dialog>
    <!--系列子品计量单位设置-->
    <el-dialog
      title="添加辅计量单位" width="50%" :visible.sync="editDialogVisible84" :close-on-click-modal="false">
      <el-form label-width="100px" :inline="true" :size="size">
        <el-form-item>
          <kt-button icon="fa fa-plus" :label="$t('action.add')" type="primary" @click="handleUnitsAdd"/>
        </el-form-item>
        <el-table :data="productUnitList" border tooltip-effect="dark" style="width: 100%">
          <el-table-column prop="name" label="计量单位"></el-table-column>
          <el-table-column prop="code" label="单位编码"></el-table-column>
          <el-table-column prop="conversionRate" label="转换率"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button :size="size" type="primary" @click="handleUnitsEdit(scope.row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--底部按钮栏-->
        <el-row id="footerButton1">
          <el-col :span="8" :offset="10">
            <el-form-item>
              <el-button :size="size" @click.native="editDialogVisible84 = false">{{ $t("action.cancel") }}</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!--添加辅计量单位弹窗-->
    <el-dialog
      title="添加辅计量单位" width="50%" :visible.sync="productUnitDialogAdd" :close-on-click-modal="false">
      <el-form :model="productUnitDialogAddForm" label-width="30%" :rules="productUnitDialogAddRules"
               ref="productUnitDialogAddForm" :size="size">
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="productUnitDialogAddForm.id" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="辅计量单位" prop="units">
          <el-select v-model="productUnitDialogAddForm.units" style="width:60%">
            <el-option
              v-for="item in productUnitDialogAddFormList"
              :key="item.id"
              :label="item.code +'-'+ item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="主计量单位">
          <label>件</label>
        </el-form-item>
        <el-form-item label="转换率(辅对主)" prop="conversionRate">
          <el-input v-model="productUnitDialogAddForm.conversionRate" auto-complete="off" style="width:60%"></el-input>
          <el-tooltip
            class="item"
            effect="dark"
            content="举例: 比如主计量单位是袋, 辅计量单位是克, 一袋对应100克, 那么转换率(辅对主)填写0.01"
            placement="top-start">
            <el-button
              size="small"
              icon="el-icon-question"
              circle></el-button>
          </el-tooltip>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button :size="size" @click.native="productUnitDialogAdd = false">{{$t("action.cancel") }}
        </el-button>
        <el-button :size="size" type="primary" @click.native="productUnitSubmitAddForm">{{ $t("action.submit") }}
        </el-button>
      </div>
    </el-dialog>
    <!--修改辅计量单位弹窗-->
    <el-dialog
      title="修改辅计量单位" width="50%" :visible.sync="productUnitDialogUpdate" :close-on-click-modal="false">
      <el-form :model="productUnitDialogUpdateForm" label-width="30%" :rules="productUnitDialogUpdateRules"
               ref="productUnitDialogUpdateForm" :size="size">
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="productUnitDialogUpdateForm.id" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="辅计量单位" prop="units">
          <el-select v-model="productUnitDialogUpdateForm.units" style="width:60%" :disabled="true">
          </el-select>
        </el-form-item>
        <el-form-item label="主计量单位">
          <label>件</label>
        </el-form-item>
        <el-form-item label="转换率(辅对主)" prop="conversionRate">
          <el-input v-model="productUnitDialogUpdateForm.conversionRate" auto-complete="off"
                    style="width:60%"></el-input>
          <el-tooltip
            class="item"
            effect="dark"
            content="举例: 比如主计量单位是袋, 辅计量单位是克, 一袋对应100克, 那么转换率(辅对主)填写0.01"
            placement="top-start">
            <el-button
              size="small"
              icon="el-icon-question"
              circle></el-button>
          </el-tooltip>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button :size="size" @click.native="productUnitDialogUpdate = false">{{$t("action.cancel") }}
        </el-button>
        <el-button :size="size" type="primary" @click.native="productUnitSubmitUpdateForm">{{ $t("action.submit") }}
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import CyTable from "@/views/Core/CyTable";
  import KtButton from "@/views/Core/KtButton";
  import {format, formatDate} from "@/utils/datetime";
  import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";

  export default {
    components: {
      KtButton,
      CyTable,
      TableColumnFilterDialog
    },
    data() {
      return {
        pictureUrlIndex:"",
        pictureUrlLimit:1,
        fileList:[],
        imgUpload: this.utils.imgUploadUrl,//商品主图
        size: "small",
        editDialogVisible10: false,
        editDialogVisible83: false,
        editDialogVisible84: false,
        editLoading: false,
        productId: 0,
        getProductParentList: [],
        getProductParentAttrList: [],
        sonProductAttrData: [],
        categoryPropertyCheckList: [],
        sonProductAttrDataList: [],
        categoryId: 0,
        productUnitList: [],
        productUnitDialogAdd: false, // 计量单位是否显示
        productUnitDialogAddForm: {
          id: '',
          units: '',
          conversionRate: ''
        },
        productUnitDialogAddFormList: [], // 计量单位 辅计量单位下拉框
        unitsProductId: '', // 系列子品计量单位和计量单位的公用productId
        codeByShopDataForm: {
          storeId: '',
          freightTemplateId: ''
        },
        productUnitDialogAddRules: {
          units: [
            {required: true, message: "请输入辅计量单位", trigger: "blur"}
          ],
          conversionRate: [
            {required: true, message: "请输入转换率(辅对主)", trigger: "blur"}
          ]
        },
        productUnitDialogUpdate: false, // 计量单位是否显示
        productUnitDialogUpdateRules: {
          units: [
            {required: true, message: "请输入辅计量单位", trigger: "blur"}
          ],
          conversionRate: [
            {required: true, message: "请输入转换率(辅对主)", trigger: "blur"}
          ]
        },
        productUnitDialogUpdateForm: {
          id: '',
          units: '',
          conversionRate: ''
        },
        repeatFlag: false,
      };
    },
    mounted() {
    },
    methods: {
      AddPictureUrl:function(index){
       this.pictureUrlIndex=index
      },
      // 商品图片上传
      handleSuccess: function (res, file) {
        if (res.code == "0000") {
          this.getProductParentList[this.pictureUrlIndex].pictureUrl=res.data.imgUrl
        }
        this.$refs.upload.clearFiles()
        this.fileList=[]
      },
      init(param) {
        this.editDialogVisible10 = param.flag
        this.productId = param.productId
        this.categoryId = param.categoryId
        if (param.flag) {
          this.handleFindProductParent()
        }
      },
      // 系列子品查询 dataType商品数据类型:1-运营商品;2-商家商品;3-店铺商品
      handleFindProductParent() {
        let this_ = this;
        let param = {}
        param.dataType = 1
        param.productId = this_.productId
        param.categoryId = this_.categoryId
        this.utils.request.getProductParent(param, function (res) {
          this_.getProductParentList = res.data;
          $.each(res.data, function (index, val) {
            if (index == 0) {
              this_.getProductParentAttrList = res.data[index].productPropertyResponseList;
              return;
            }
          })
        });
      },
      handleEditSonProductAttr() {
        //类目属性查询
        let this_ = this;
        this_.sonProductAttrDataList = [];
        this_.editDialogVisible83 = true;
        let param = {};
        param.productId = this_.productId;
        param.categoryId = this_.categoryId;
        this.utils.request.queryProductCategory(param, function (data) {
          if (data.data != null) {
            this_.sonProductAttrData = data.data;
            $.each(data.data, function (index, val) {
              this_.categoryPropertyCheckList[index] = [];
            })
          }
        })
      },
      cancelEditSonProductAttr() {
        this.sonProductAttrDataList = [];
        this.editDialogVisible83 = false;
      },
      //系列品选择
      saveSonProductAttrDataList() {
        if (this.categoryPropertyCheckList.length > 0) {
          //总行数
          let totalRow = 1;
          let this_ = this;
          //存放SKU类型的数组
          let skuTypeArr = [];
          for (let i = 0; i < this.categoryPropertyCheckList.length; i++) {
            if (this.categoryPropertyCheckList[i] == 0) {
              this_.sonProductAttrDataList = [];
              this_.$message({message: "非新建子品时，需要选择所有属性", type: "warning"});
              return;
            }
          }
          $.each(this.sonProductAttrData, function (index, val1) {
            let categoryPropertyValueResponseList = val1.categoryPropertyValueResponseList;
            let categoryPropertyCheckList = this_.categoryPropertyCheckList[index];
            let skuTypeObj = {};//sku类型对象
            //SKU属性类型标题
            skuTypeObj.attrName = val1.attrName;
            skuTypeObj.attrId = val1.attrId;
            let skuValueArr = [];//存放SKU值得数组
            $.each(categoryPropertyValueResponseList, function (index, val3) {
              $.each(categoryPropertyCheckList, function (index, val2) {
                if (val2 == val3.valueId) {
                  let skuValObj = {};//SKU值对象
                  skuValObj.valueId = val3.valueId;//SKU值名称
                  skuValObj.valueName = val3.valueName;//SKU值主键
                  skuValueArr.push(skuValObj);
                }
              });
            });
            if (skuValueArr && skuValueArr.length > 0) {
              totalRow = totalRow * skuValueArr.length;
              skuTypeObj.skuValues = skuValueArr;//sku值数组
              skuTypeObj.skuValueLen = skuValueArr.length;//sku值长度
              skuTypeArr.push(skuTypeObj);//保存进数组中
            }
          });
          let skuList = [];
          for (let i = 0; i < totalRow; i++) {
            let rowCount = 1;//记录行数
            let attList = {};//SKU值对象
            let attList1 = [];
            for (let j = 0; j < skuTypeArr.length; j++) {
              let skuValues = skuTypeArr[j].skuValues;//SKU值数组
              let skuValueLen = skuValues.length;//sku值长度
              rowCount = (rowCount * skuValueLen);//目前的生成的总行数
              let anInterBankNum = (totalRow / rowCount);//跨行数
              let point = ((i / anInterBankNum) % skuValueLen);
              let skuValObj = {};//SKU值对象
              skuValObj.attr = skuTypeArr[j].attrName + ":" + skuValues[parseInt(point)].valueName;
              skuValObj.valueName = skuValues[parseInt(point)].valueName;
              skuValObj.valueId = skuValues[parseInt(point)].valueId;
              skuValObj.attrName = skuTypeArr[j].attrName;
              skuValObj.attrId = skuTypeArr[j].attrId;
              attList1.push(skuValObj)
            }
            if (attList1.length > 0) {
              attList.attList = attList1;
              skuList.push(attList);
            }
          }
          this_.sonProductAttrDataList = skuList;
          //判断重复操作
          if (this_.getProductParentList.length > 0) {
            for (let i = 0; i < this_.getProductParentList.length; i++) {
              //比较重复的数据
              let compare = [];
              for (let j = 0; j < this_.getProductParentList[i].productPropertyResponseList.length; j++) {
                //数据里的sku值
                let productPropertyResponseList = this_.getProductParentList[i].productPropertyResponseList[j];
                compare.push(productPropertyResponseList.valueId);

              }
              for (let k = 0; k < this_.sonProductAttrDataList.length; k++) {
                //比较重复的数据
                let compare2 = [];
                for (let f = 0; f < this_.sonProductAttrDataList[k].attList.length; f++) {
                  let attList = this_.sonProductAttrDataList[k].attList[f];
                  compare2.push(attList.valueId)
                }
                if (JSON.stringify(compare) == JSON.stringify(compare2)) {
                  this_.sonProductAttrDataList[k].attList[0].repeat = "重复";
                }
              }
            }

          }else {

          }
        }
      },
      // 删除系列子品属性值
      handleDeleteCategoryProperty: function (index, row) {
        let this_ = this;
        this_.sonProductAttrDataList.splice(index, 1)
      },
      submitSonProductAttrDataList() {
        let this_ = this;
        if (this_.sonProductAttrDataList.length > 0) {
          //判断重复操作
            for (let i = 0; i < this_.getProductParentList.length; i++) {
              //比较重复的数据
              let compare = [];
              for (let j = 0; j < this_.getProductParentList[i].productPropertyResponseList.length; j++) {
                //数据里的sku值
                let productPropertyResponseList = this_.getProductParentList[i].productPropertyResponseList[j];
                compare.push(productPropertyResponseList.valueId);

              }
              for (let k = 0; k < this_.sonProductAttrDataList.length; k++) {
                //比较重复的数据
                let compare2 = [];
                for (let f = 0; f < this_.sonProductAttrDataList[k].attList.length; f++) {
                  let attList = this_.sonProductAttrDataList[k].attList[f];
                  compare2.push(attList.valueId)
                }
                if (JSON.stringify(compare) == JSON.stringify(compare2)) {
                  this_.$message({message: "请重新生成系列子品", type: "warning"});
                  return;
                }
              }
            }
            let params = {}
            params.productId = this_.productId;
            params.productPropertyRequest = this_.sonProductAttrDataList;
            this.utils.request.saveProductParent(params, function (data) {
              if (data.code == "0000") {
                this_.editDialogVisible83 = false;
                this_.handleFindProductParent();
                this_.$message({message: "操作成功", type: "success"});
              } else {
                this_.$message({message: "操作失败, " + data.message, type: "error"});
              }
            });
        }
      },
      // 系列子品删除
      handleDeleteProductParent(data) {
        let this_ = this;
        this.utils.request.deleteProductParent({productId: data.id}, function (res) {
          if (res.code == "0000") {
            this_.handleFindProductParent();
            this_.$message({message: "操作成功", type: "success"});
          } else {
            this_.$message({
              message: "操作失败",
              type: "error"
            });
          }
        });
      }
      ,
      // 系列子品修改
      handleUpdateProductParent() {
        let this_ = this;
        let params = {};
        params.dataType = 1;
        let productDistributeStoreParentRequestList = [];
        for (let i = 0; i < this_.getProductParentList.length; i++) {
          let val=this_.getProductParentList[i]
          if (val != null && val != '') {
            let list = {};
            list.productId = val.id;
            if (val.salePriceWithTax==0){
              this.$message.info("不能为空")
              return;
            }
            list.salePriceWithTax = val.salePriceWithTax;
            list.groupBuyingPrice = val.groupBuyingPrice;
            list.marketPrice = val.marketPrice;
            list.purchasePriceWithTax = val.purchasePriceWithTax;
            list.thirdProductCode = val.thirdProductCode;
            list.barCode = val.barCode;
            list.pictureUrl=val.pictureUrl
            list.totalStock=val.totalStock
            list.availableStock=val.availableStock
            productDistributeStoreParentRequestList.push(list);
          }
        }
        /*$.each(this_.getProductParentList, function (index, val) {

        });*/
        params.productDistributeStoreParentRequestList = productDistributeStoreParentRequestList;
        this.utils.request.updateProductParentPrice(params, function (res) {
          if (res.code == "0000") {
            this_.handleFindProductParent();
            this_.$message({message: "操作成功", type: "success"});
          } else {
            this_.$message({
              message: "操作失败",
              type: "error"
            });
          }
        });
      }
      ,
      // 系列子品设置 -计量单位查询
      handleEditUnits(data) {
        this.unitsProductId = data.id;
        this.handleUnitsFind(data.id);
        this.editDialogVisible84 = true;
      }
      ,
      // 计量单位查询、添加、修改
      handleUnitsFind(id) {
        let this_ = this;
        this.utils.request.queryProductUnitsRelation({productId: id}, function (res) {
          this_.productUnitList = res.data;
        });
      }
      ,
      handleUnitsAdd() {
        let this_ = this;
        this_.productUnitDialogAddForm = {};
        if (this_.productUnitList.length < 1) {
          this.utils.request.queryProductUnitsList(null, function (res) {
            this_.productUnitDialogAddFormList = res.data;
          });
        } else {
          this_.productUnitDialogAddFormList = null;
        }
        this_.productUnitDialogAdd = true;
      }
      ,
      productUnitSubmitAddForm() {
        this.$refs.productUnitDialogAddForm.validate(valid => {
          if (valid) {
            this.$confirm("确认提交吗？", "提示", {}).then(() => {
              let params = {};
              let this_ = this;
              params.productId = this.unitsProductId;
              params.dataType = 3;
              params.productUnitsId = this.productUnitDialogAddForm.units;
              params.conversionRate = this.productUnitDialogAddForm.conversionRate;
              this.utils.request.addProductUnitsRelation(params, function (res) {
                if (res.code == "0000") {
                  this_.$message({message: "操作成功", type: "success"});
                  this_.handleUnitsFind(params.productId);
                  this_.productUnitDialogAdd = false
                } else {
                  this_.$message({
                    message: "操作失败",
                    type: "error"
                  });
                }
              });
            });
          }
        });
      }
      ,
      handleUnitsEdit(params) {
        this.productUnitDialogUpdate = true;
        this.productUnitDialogUpdateForm.id = params.id;
        this.productUnitDialogUpdateForm.units = params.name + '-' + params.code;
        this.productUnitDialogUpdateForm.conversionRate = params.conversionRate;
      }
      ,
      productUnitSubmitUpdateForm() {
        this.$refs.productUnitDialogUpdateForm.validate(valid => {
          if (valid) {
            this.$confirm("确认提交吗？", "提示", {}).then(() => {
              let params = {};
              let this_ = this;
              params.id = this.productUnitDialogUpdateForm.id;
              params.dataType = 3;
              params.conversionRate = this.productUnitDialogUpdateForm.conversionRate;
              this.utils.request.updateProductUnitsRelation(params, function (res) {
                if (res.code == "0000") {
                  this_.$message({message: "操作成功", type: "success"});
                  this_.handleUnitsFind(this_.unitsProductId);
                  this_.productUnitDialogUpdate = false
                } else {
                  this_.$message({
                    message: "操作失败",
                    type: "error"
                  });
                }
              });
            })
          }
        });
      }
      ,
    }
  };
</script>

<style scoped>

</style>
